/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jFContas.java
 *
 * Created on 09/04/2011, 01:37:29
 */

package sgfi;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;
import javax.swing.KeyStroke;
import javax.swing.table.DefaultTableModel;
import sgfi.Classes.ClassConecta;
import sgfi.Classes.ComboItem;
import sgfi.Classes.Comunidade;
import sgfi.Classes.Contas;
import sgfi.Classes.Funcoes;

/**
 *
 * @author vitiazze
 */
public class jFContas extends javax.swing.JFrame {
   

    /** Creates new form jFContas */
    public jFContas() {
        initComponents();
        JRootPane meurootpane = getRootPane();
        meurootpane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ESCAPE");
        meurootpane.getRootPane().getActionMap().put("ESCAPE", new AbstractAction("ESCAPE") {

            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        buscarjButton = new javax.swing.JButton();
        novojButton = new javax.swing.JButton();
        editarjButton = new javax.swing.JButton();
        salvarjButton = new javax.swing.JButton();
        alterarjButton = new javax.swing.JButton();
        excluirjButton = new javax.swing.JButton();
        sairjButton = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        codigojSpinner = new javax.swing.JSpinner();
        ativojComboBox = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        bancojTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        numeroBancojSpinner = new javax.swing.JSpinner();
        agenciaBancojSpinner = new javax.swing.JSpinner();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        digitoAgenciajSpinner = new javax.swing.JSpinner();
        numeroContajSpinner = new javax.swing.JSpinner();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        contajTextField = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        observacaojTextArea = new javax.swing.JTextArea();
        comunidadejComboBox = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        digitoContajTextField = new javax.swing.JTextField();
        atualizarjButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        contajTable = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sgfi.SGFIApp.class).getContext().getResourceMap(jFContas.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        buscarjButton.setIcon(resourceMap.getIcon("buscarjButton.icon")); // NOI18N
        buscarjButton.setText(resourceMap.getString("buscarjButton.text")); // NOI18N
        buscarjButton.setFocusable(false);
        buscarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buscarjButton.setName("buscarjButton"); // NOI18N
        buscarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buscarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(buscarjButton);

        novojButton.setIcon(resourceMap.getIcon("novojButton.icon")); // NOI18N
        novojButton.setText(resourceMap.getString("novojButton.text")); // NOI18N
        novojButton.setToolTipText(resourceMap.getString("novojButton.toolTipText")); // NOI18N
        novojButton.setFocusable(false);
        novojButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        novojButton.setName("novojButton"); // NOI18N
        novojButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        novojButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novojButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(novojButton);

        editarjButton.setIcon(resourceMap.getIcon("editarjButton.icon")); // NOI18N
        editarjButton.setText(resourceMap.getString("editarjButton.text")); // NOI18N
        editarjButton.setToolTipText(resourceMap.getString("editarjButton.toolTipText")); // NOI18N
        editarjButton.setFocusable(false);
        editarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editarjButton.setName("editarjButton"); // NOI18N
        editarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        editarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(editarjButton);

        salvarjButton.setIcon(resourceMap.getIcon("salvarjButton.icon")); // NOI18N
        salvarjButton.setText(resourceMap.getString("salvarjButton.text")); // NOI18N
        salvarjButton.setToolTipText(resourceMap.getString("salvarjButton.toolTipText")); // NOI18N
        salvarjButton.setFocusable(false);
        salvarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        salvarjButton.setName("salvarjButton"); // NOI18N
        salvarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        salvarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(salvarjButton);

        alterarjButton.setIcon(resourceMap.getIcon("alterarjButton.icon")); // NOI18N
        alterarjButton.setText(resourceMap.getString("alterarjButton.text")); // NOI18N
        alterarjButton.setToolTipText(resourceMap.getString("alterarjButton.toolTipText")); // NOI18N
        alterarjButton.setFocusable(false);
        alterarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        alterarjButton.setName("alterarjButton"); // NOI18N
        alterarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        alterarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                alterarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(alterarjButton);

        excluirjButton.setIcon(resourceMap.getIcon("excluirjButton.icon")); // NOI18N
        excluirjButton.setText(resourceMap.getString("excluirjButton.text")); // NOI18N
        excluirjButton.setToolTipText(resourceMap.getString("excluirjButton.toolTipText")); // NOI18N
        excluirjButton.setFocusable(false);
        excluirjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        excluirjButton.setName("excluirjButton"); // NOI18N
        excluirjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        excluirjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                excluirjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(excluirjButton);

        sairjButton.setIcon(resourceMap.getIcon("sairjButton.icon")); // NOI18N
        sairjButton.setText(resourceMap.getString("sairjButton.text")); // NOI18N
        sairjButton.setToolTipText(resourceMap.getString("sairjButton.toolTipText")); // NOI18N
        sairjButton.setFocusable(false);
        sairjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sairjButton.setName("sairjButton"); // NOI18N
        sairjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        sairjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(sairjButton);

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        codigojSpinner.setName("codigojSpinner"); // NOI18N

        ativojComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sim", "Não" }));
        ativojComboBox.setName("ativojComboBox"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        bancojTextField.setName("bancojTextField"); // NOI18N
        bancojTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                bancojTextFieldKeyReleased(evt);
            }
        });

        jLabel2.setForeground(resourceMap.getColor("jLabel2.foreground")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        numeroBancojSpinner.setName("numeroBancojSpinner"); // NOI18N

        agenciaBancojSpinner.setName("agenciaBancojSpinner"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        digitoAgenciajSpinner.setName("digitoAgenciajSpinner"); // NOI18N

        numeroContajSpinner.setName("numeroContajSpinner"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        contajTextField.setText(resourceMap.getString("contajTextField.text")); // NOI18N
        contajTextField.setName("contajTextField"); // NOI18N

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        observacaojTextArea.setColumns(20);
        observacaojTextArea.setRows(5);
        observacaojTextArea.setName("observacaojTextArea"); // NOI18N
        observacaojTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                observacaojTextAreaKeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(observacaojTextArea);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                .addContainerGap())
        );

        comunidadejComboBox.setName("comunidadejComboBox"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        digitoContajTextField.setText(resourceMap.getString("digitoContajTextField.text")); // NOI18N
        digitoContajTextField.setName("digitoContajTextField"); // NOI18N

        atualizarjButton.setIcon(resourceMap.getIcon("atualizarjButton.icon")); // NOI18N
        atualizarjButton.setText(resourceMap.getString("atualizarjButton.text")); // NOI18N
        atualizarjButton.setName("atualizarjButton"); // NOI18N
        atualizarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizarjButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(codigojSpinner, javax.swing.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)
                                    .addComponent(jLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addGap(79, 79, 79)
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(digitoContajTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                                .addComponent(jLabel7))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel10)
                                                .addComponent(ativojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addComponent(bancojTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE))))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(digitoAgenciajSpinner)
                                    .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(numeroContajSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6))))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(contajTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
                                            .addComponent(jLabel17))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(numeroBancojSpinner)
                                            .addComponent(jLabel3)))
                                    .addComponent(comunidadejComboBox, 0, 264, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(atualizarjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(agenciaBancojSpinner)
                                        .addComponent(jLabel4))))
                            .addComponent(jLabel8))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel17)
                                    .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(bancojTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(codigojSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(contajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5)
                                .addComponent(jLabel6))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(atualizarjButton)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel8)
                                        .addComponent(jLabel10)
                                        .addComponent(jLabel7))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(digitoAgenciajSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(numeroContajSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(comunidadejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(ativojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(digitoContajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(numeroBancojSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(agenciaBancojSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        contajTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Banco", "Igreja", "Nome da conta", "Agência", "Conta"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        contajTable.setName("contajTable"); // NOI18N
        contajTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                contajTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(contajTable);
        contajTable.getColumnModel().getColumn(0).setResizable(false);
        contajTable.getColumnModel().getColumn(0).setPreferredWidth(50);
        contajTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("contajTable.columnModel.title0")); // NOI18N
        contajTable.getColumnModel().getColumn(1).setResizable(false);
        contajTable.getColumnModel().getColumn(1).setPreferredWidth(100);
        contajTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("contajTable.columnModel.title1")); // NOI18N
        contajTable.getColumnModel().getColumn(2).setResizable(false);
        contajTable.getColumnModel().getColumn(2).setPreferredWidth(150);
        contajTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("contajTable.columnModel.title2")); // NOI18N
        contajTable.getColumnModel().getColumn(3).setResizable(false);
        contajTable.getColumnModel().getColumn(3).setPreferredWidth(90);
        contajTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("contajTable.columnModel.title5")); // NOI18N
        contajTable.getColumnModel().getColumn(4).setResizable(false);
        contajTable.getColumnModel().getColumn(4).setPreferredWidth(80);
        contajTable.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("contajTable.columnModel.title3")); // NOI18N
        contajTable.getColumnModel().getColumn(5).setResizable(false);
        contajTable.getColumnModel().getColumn(5).setPreferredWidth(80);
        contajTable.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("contajTable.columnModel.title4")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE))
                    .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 660, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 405, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public ClassConecta conexao = new ClassConecta();

    ComboItem comboComunidade;

    public int codConta;


       public void getGrandeContas() throws ParseException{
       //Consultar pedidos
        Contas oConta = new Contas();

        if ( bancojTextField.getText().length() > 0 ){
            oConta.setBanco(bancojTextField.getText()+"%");
        }

        ResultSet resultSet = null;

        String[] colunasTabela = new String[]{"Código", "Banco", "Igreja","Nome da conta", "Agência", "Conta"};
        DefaultTableModel modeloTabela = new DefaultTableModel(null, colunasTabela) {

            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        };
        contajTable.setModel(modeloTabela);
        contajTable.getColumnModel().getColumn(0).setPreferredWidth(50);
        contajTable.getColumnModel().getColumn(1).setPreferredWidth(100);
        contajTable.getColumnModel().getColumn(2).setPreferredWidth(150);
        contajTable.getColumnModel().getColumn(3).setPreferredWidth(90);
        contajTable.getColumnModel().getColumn(4).setPreferredWidth(80);
        contajTable.getColumnModel().getColumn(5).setPreferredWidth(80);



try {
            resultSet = oConta.getConsultar();
            if (resultSet.getRow() == 1){
             resultSet.first();
            }


        } catch (SQLException ex) {
            Logger.getLogger(Contas.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {

                modeloTabela.addRow(new String[]{
                    Funcoes.getCodigoFormat(resultSet.getInt("codConta")),
                    resultSet.getString("banco"),
                    resultSet.getString("NomeComunidade"),
                    resultSet.getString("conta"),
                    resultSet.getInt("agencia")+"-"+resultSet.getInt("digitoAgencia"),
                    resultSet.getInt("numeroConta")+"-"+resultSet.getInt("digitoConta"),
                });

            }

        } catch (SQLException ex) {
            Logger.getLogger(Comunidade.class.getName()).log(Level.SEVERE, null, ex);
        }

           }
       public void getFieldConta(int codConta) throws ParseException{

        Contas oConta = new Contas();
        ResultSet rs = null;
        oConta.setCodConta(codConta);

        try {
            rs = oConta.getConsultar();
            rs.next();

            ComboItem oItem = new ComboItem(rs.getInt("codComunidade"), rs.getString("nomeComunidade"));
            comunidadejComboBox.setSelectedItem(oItem);
            //Pegar campos
            codigojSpinner.setValue(rs.getInt("codConta"));
            bancojTextField.setText(rs.getString("banco"));
            agenciaBancojSpinner.setValue(rs.getInt("agencia"));
            digitoAgenciajSpinner.setValue(rs.getInt("digitoAgencia"));
            numeroContajSpinner.setValue(rs.getInt("numeroConta"));
            digitoContajTextField.setText(rs.getString("digitoConta"));
            ativojComboBox.setSelectedItem(rs.getString("ativo"));
            contajTextField.setText(rs.getString("conta"));
            numeroBancojSpinner.setValue(rs.getInt("numeroBanco"));
            observacaojTextArea.setText(rs.getString("observacao"));

        } catch (SQLException ex) {
            Logger.getLogger(Contas.class.getName()).log(Level.SEVERE, null, ex);
        }



    }



    private void sairjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairjButtonActionPerformed
        // TODO add your handling code here:
        if (salvarjButton.isEnabled()){
            Object[] options = {"Sim", "Não"};
        int sd =
                JOptionPane.showOptionDialog(
                null,
                "Deseja realmente Sair sem salvar?\nAs informações não salvas serão perdidas!",
                "Confirmação!",
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.WARNING_MESSAGE,
                null,
                options,
                options[0]);

        if (sd != 0) {
            return;
        }
        this.dispose();

        }else{
            this.dispose();
        }
    }//GEN-LAST:event_sairjButtonActionPerformed

    private void atualizarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizarjButtonActionPerformed
        try {
            // TODO add your handling code here:
            Comunidade oComunidade = new Comunidade();
            ResultSet rs = null;
            rs = oComunidade.getConsultar();
            comunidadejComboBox.removeAllItems();
            while (rs.next()) {
                comunidadejComboBox.addItem(new ComboItem(rs.getInt(1), rs.getString(2)));
            }
            comunidadejComboBox.updateUI();
        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_atualizarjButtonActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        conexao.conecta();
        atualizarjButtonActionPerformed(null);
        buscarjButtonActionPerformed(null);
        bancojTextField.grabFocus();

                    salvarjButton.setEnabled(false);
                    alterarjButton.setEnabled(false);
                    excluirjButton.setEnabled(false);
                    editarjButton.setEnabled(false);
                    novojButton.setEnabled(true);
    }//GEN-LAST:event_formWindowOpened

    private void novojButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novojButtonActionPerformed
        // TODO add your handling code here:
        novojButton.setEnabled(false);
        alterarjButton.setEnabled(false);
        editarjButton.setEnabled(false);
        excluirjButton.setEnabled(false);
        buscarjButton.setEnabled(true);
        salvarjButton.setEnabled(true);
        codigojSpinner.setEnabled(false);
        bancojTextField.grabFocus();
        try {
            ClassConecta.con.setAutoCommit(false);
        } catch (SQLException ex) {
            Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
        }
        bancojTextField.setText("");
        contajTextField.setText("");
        numeroBancojSpinner.setValue(0);
        agenciaBancojSpinner.setValue(0);
        digitoAgenciajSpinner.setValue(0);
        numeroContajSpinner.setValue(0);
        digitoContajTextField.setText("");
        ativojComboBox.setSelectedItem("Sim");
    }//GEN-LAST:event_novojButtonActionPerformed

    private void salvarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarjButtonActionPerformed
        try {
            // TODO add your handling code here:


            comboComunidade = (ComboItem) comunidadejComboBox.getSelectedItem();

            if (bancojTextField.getText().equals("")){

                JOptionPane.showMessageDialog(null, "Preencha os campos \nBanco e Nome da Conta", "ATENÇÃO", JOptionPane.WARNING_MESSAGE);
            }else{
                
            salvarjButton.setEnabled(false);
            alterarjButton.setEnabled(false);
            excluirjButton.setEnabled(false);
            novojButton.setEnabled(true);
            editarjButton.setEnabled(true);
            
            Contas oConta = new Contas();

            oConta.setBanco(bancojTextField.getText());
            oConta.setConta(contajTextField.getText());
            oConta.setNumeroBanco((Integer) numeroBancojSpinner.getValue());
            oConta.setAgencia((Integer) agenciaBancojSpinner.getValue());
            oConta.setDigitoAgencia((Integer) digitoAgenciajSpinner.getValue());
            oConta.setNumeroConta((Integer) numeroContajSpinner.getValue());
            oConta.setDigitoConta(digitoContajTextField.getText());
            oConta.setAtivo((String) ativojComboBox.getSelectedItem());
            oConta.setCodComunidade(comboComunidade.getId());
            oConta.setObservacao(observacaojTextArea.getText());
            
            
            oConta.setCadastrar();

            bancojTextField.grabFocus();

            ClassConecta.con.commit();
            ClassConecta.con.setAutoCommit(true);

            getGrandeContas();
            
            int cod_conta = oConta.getId();
            Funcoes.getItemJTable(cod_conta, contajTable);

        }} catch (ParseException ex) {
            Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
        }

        

            

    }//GEN-LAST:event_salvarjButtonActionPerformed

    private void buscarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarjButtonActionPerformed
        try {
            // TODO add your handling code here:
            getGrandeContas();
        } catch (ParseException ex) {
            Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buscarjButtonActionPerformed

    private void contajTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_contajTableMouseClicked
        // TODO add your handling code here:
            editarjButton.setEnabled(true);
            codConta = Integer.parseInt(contajTable.getValueAt(contajTable.getSelectedRow(), 0).toString());
            if (codConta == 0) {
                return;
            }
        try {
            getFieldConta(codConta);
        } catch (ParseException ex) {
            Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_contajTableMouseClicked

    private void observacaojTextAreaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_observacaojTextAreaKeyTyped
        // TODO add your handling code here:
        observacaojTextArea.setLineWrap(true);
        observacaojTextArea.setWrapStyleWord(true);
    }//GEN-LAST:event_observacaojTextAreaKeyTyped

    private void bancojTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_bancojTextFieldKeyReleased
        // TODO add your handling code here:
                if (!alterarjButton.isEnabled()){
            try {
                Contas oConta = new Contas();
                oConta.setBanco(bancojTextField.getText());
                ResultSet rs = null;
                rs = oConta.getConsultar();
                getGrandeContas();
            } catch (ParseException ex) {
                Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
                    }
    }
                if(bancojTextField.getText().equals("")){
        bancojTextField.setText("");
        contajTextField.setText("");
        numeroBancojSpinner.setValue(0);
        agenciaBancojSpinner.setValue(0);
        digitoAgenciajSpinner.setValue(0);
        numeroContajSpinner.setValue(0);
        digitoContajTextField.setText("");
        ativojComboBox.setSelectedItem("Sim");
        observacaojTextArea.setText("");
        codigojSpinner.setValue(0);
                }
    }//GEN-LAST:event_bancojTextFieldKeyReleased

    private void editarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarjButtonActionPerformed
        // TODO add your handling code here:
            novojButton.setEnabled(false);
            salvarjButton.setEnabled(false);
            editarjButton.setEnabled(false);
            alterarjButton.setEnabled(true);
            excluirjButton.setEnabled(true);
        try {
            ClassConecta.con.setAutoCommit(false);
        } catch (SQLException ex) {
            Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_editarjButtonActionPerformed

    private void alterarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alterarjButtonActionPerformed
        try {
            // TODO add your handling code here:
            alterarjButton.setEnabled(false);
            editarjButton.setEnabled(true);
            excluirjButton.setEnabled(false);
            novojButton.setEnabled(true);
            comboComunidade = (ComboItem) comunidadejComboBox.getSelectedItem();
            @SuppressWarnings(value = "LocalVariableHidesMemberVariable")

            int codConta = 0;
            codConta = Integer.parseInt(contajTable.getValueAt(contajTable.getSelectedRow(), 0).toString());

            Contas oConta = new Contas();
            oConta.setCodConta(codConta);

            oConta.setBanco(bancojTextField.getText());
            oConta.setConta(contajTextField.getText());
            oConta.setNumeroBanco((Integer) numeroBancojSpinner.getValue());
            oConta.setAgencia((Integer) agenciaBancojSpinner.getValue());
            oConta.setDigitoAgencia((Integer) digitoAgenciajSpinner.getValue());
            oConta.setNumeroConta((Integer) numeroContajSpinner.getValue());
            oConta.setDigitoConta(digitoContajTextField.getText());
            oConta.setAtivo((String) ativojComboBox.getSelectedItem());
            oConta.setCodComunidade(comboComunidade.getId());
            oConta.setObservacao(observacaojTextArea.getText());
            oConta.setAlterar(conexao);

            getGrandeContas();
        } catch (ParseException ex) {
            Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            ClassConecta.con.commit();
            ClassConecta.con.setAutoCommit(true);
        } catch (SQLException ex) {
            Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
        }
        Funcoes.getItemJTable(codConta, contajTable);
        
    }//GEN-LAST:event_alterarjButtonActionPerformed

    private void excluirjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excluirjButtonActionPerformed
        // TODO add your handling code here:
         Object[] options = {"Sim", "Não"};
        int sd =
                JOptionPane.showOptionDialog(
                null,
                "Deseja realmente EXCLUIR esta conta?",
                "Confirmação!",
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.WARNING_MESSAGE,
                null,
                options,
                options[0]);

        if (sd != 0) {
            return;
        }
        alterarjButton.setEnabled(false);
        editarjButton.setEnabled(true);
        excluirjButton.setEnabled(false);
        novojButton.setEnabled(true);

        int codContaDelete = 0;
        codContaDelete = Integer.parseInt(contajTable.getValueAt(contajTable.getSelectedRow(), 0).toString());

        Contas oConta = new Contas();
        oConta.setCodConta(codContaDelete);
        oConta.setExcluir(conexao);
        try {
            ClassConecta.con.commit();
            ClassConecta.con.setAutoCommit(true);
        } catch (SQLException ex) {
            Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            getGrandeContas();
        } catch (ParseException ex) {
            Logger.getLogger(jFContas.class.getName()).log(Level.SEVERE, null, ex);
        }

        bancojTextField.setText("");
        contajTextField.setText("");
        numeroBancojSpinner.setValue(0);
        agenciaBancojSpinner.setValue(0);
        digitoAgenciajSpinner.setValue(0);
        numeroContajSpinner.setValue(0);
        digitoContajTextField.setText("");
        ativojComboBox.setSelectedItem("Sim");
        observacaojTextArea.setText("");



    }//GEN-LAST:event_excluirjButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jFContas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSpinner agenciaBancojSpinner;
    private javax.swing.JButton alterarjButton;
    private javax.swing.JComboBox ativojComboBox;
    private javax.swing.JButton atualizarjButton;
    private javax.swing.JTextField bancojTextField;
    private javax.swing.JButton buscarjButton;
    private javax.swing.JSpinner codigojSpinner;
    private javax.swing.JComboBox comunidadejComboBox;
    private javax.swing.JTable contajTable;
    private javax.swing.JTextField contajTextField;
    private javax.swing.JSpinner digitoAgenciajSpinner;
    private javax.swing.JTextField digitoContajTextField;
    private javax.swing.JButton editarjButton;
    private javax.swing.JButton excluirjButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton novojButton;
    private javax.swing.JSpinner numeroBancojSpinner;
    private javax.swing.JSpinner numeroContajSpinner;
    private javax.swing.JTextArea observacaojTextArea;
    private javax.swing.JButton sairjButton;
    private javax.swing.JButton salvarjButton;
    // End of variables declaration//GEN-END:variables

}
